#include <Message.h>


namespace util::message{
    // std::future<bool> IMessageHandler::AsyncReceive(MessageType msg, void * param){
    //     return std::async([this](MessageType msg, void * param){
    //         return this->Receive(msg, param);
    //     }, msg, param);
    // }

    bool IUniqueMessageHandler::SetPtr(IUniqueMessageHandler ** pptr){
        if (this->pptr != nullptr){
            if(*(this->pptr) != nullptr){
                (*this->pptr) = nullptr;
            }
        }
       this->pptr = pptr;
        (*this->pptr) = this;
        return true;
    }

    IMessageHandler * IUniqueMessageHandler::Expose(){
        return static_cast<IMessageHandler*>(this);
    }

    Event::Event(MessageType msg) : msg(msg){}

    bool Event::AddListener(IMessageHandler * phandler){
        handler_list.push_back(phandler);
        return true;
    }

    void Event::Invoke(void * param){
        for (auto handler : handler_list){
            handler->Receive(msg, param);
        }
    }

    // void AsyncEvent::Invoke(void * param){
    //     for (auto handler : handler_list){
    //         handler->AsyncReceive(msg, param);
    //     }
    // }
}